import {
  HealthDescEnum,
  HealthEnum,
  V3proPanelStatusEnum,
} from "../../task/v3pro-task/model/v3pro.enum";
import { Record } from "../../model/common.model";

export interface V3proPageResult<T> {
  total: {
    count: number;
    offset: number;
  };
  requestDatas: T;
}

export interface V3proScreen {
  id: string;
  name: string;
  type: number;
  typeName: string;
  model: string;
}

export interface V3proLayout extends Record {
  width: number;
  height: number;
  x: number;
  y: number;
}

export interface V3proHeath {
  health: HealthEnum;
  healthDesc: {
    status: HealthEnum;
    description: HealthDescEnum[];
  };
}

export interface V3proSta {
  receivedUpdFrame: boolean;
  hasErrorCode: boolean;
  linked: boolean;
  bandWidth: string;
  linkChangeCount: number;
  netChipConfSuccess: boolean;
  interfaceIndex: number;
  name: string;
  queryTime: string;
  healthStatus: "OK" | "ERROR" | "UNKNOWN";
}

export interface V3proCommunication {
  communication: {
    control: {
      status: "OK" | "ERROR";
    };
    interfacesSta: V3proSta[];
    opticalFibersSta: V3proSta[];
  };
}

export interface V3proRunStatus {
  runStatus: {
    voltages: Array<{
      name: string;
      value: string;
      index: number;
    }>;
    workingTempC: number;
    uptimeS: number;
    queryTime: string;
    queryTimeMS: number;
    doorOpen?: string;
  };
}

/**
 * layout 在 {@link V3proSendBoxScanBoard} 中
 * 在 {@link V3proSendBoxScanBoard} 中
 */
export interface V3proSendboxScanBoardLayout extends V3proLayout {}

/**
 * 面板坏点情况
 */
export interface V3PanelBadPixel {
  panelIndex?: number;
  totalPixelCount?: number;
  redBadPixelCount?: number;
  greenBadPixelCount?: number;
  blueBadPixelCount?: number;
  checkTime?: string;
}

/**
 * 扫描板面板
 */
export interface V3proSendBoxScanBoardPanel extends Record, V3proHeath {
  name: string;
  index: number;
  status: V3proPanelStatusEnum;
  queryTime: string;
  scanSignalErr?: boolean;
  details?: {
    index: number;
    linkStatus: {
      signal_s: V3proPanelStatusEnum;
      dataPath: V3proPanelStatusEnum;
    };
    fanStatus: V3proPanelStatusEnum;
    brightData: V3proPanelStatusEnum;
    power_v: string;
    uptime_h: string;
    queryTime: string;
  };

  /**
   * 这两个是额外添加的，原始数据中不存在
   * 做完累计操作之后有效 {@link V3proAllStatusLambda#accAllStatusXY }
   */
  x?: number;
  y?: number;
  badCount?: number;
  panelBadPixels?: V3PanelBadPixel;
}

export interface V3proSendBoxScanBoardStatus
  extends V3proHeath,
    V3proCommunication,
    V3proRunStatus {
  panels: V3proSendBoxScanBoardPanel[];
  panelConf: {
    width: number;
    height: number;
  };
  badPixel: {
    panelBadPixelArr: V3PanelBadPixel[];
  };
}

/**
 * 扫描板
 * 在 {@link V3proSendBox} 中
 */
export interface V3proSendBoxScanBoard extends Record {
  deviceInfo: {
    id: string;
    name: string;
    addr: string;
  };
  addr: string;
  status: V3proSendBoxScanBoardStatus;
  layout: V3proSendboxScanBoardLayout;
}

export interface V3proSendBoxOutPort extends V3proLayout {
  originationIP: string;
  name: string;
  sendBoxIp: string;
  scanBoards: Array<{
    id: string;
    x?: number;
    y?: number;
  }>;
}

export interface V3proSendBoxLayout extends V3proLayout {
  outPorts: V3proSendBoxOutPort[];
  outputMode: "net port" | "optical fiber";
}

export interface V3proSendBoxStatus extends V3proHeath, V3proCommunication, V3proRunStatus {
  ioInputArr: Array<{
    status: "unknown" | "on" | "off";
  }>;
}

/**
 * 发送盒采集信息
 * 在 {@link V3proScreenAllStatus} 中
 */
export interface V3proSendBox extends Record {
  deviceInfo: {
    id: string;
    name: string;
    addr: string;
  };
  addr: string;
  status: V3proSendBoxStatus;
  scanBoards: V3proSendBoxScanBoard[];
  layout: V3proSendBoxLayout;
}

/**
 * 屏幕采集 layout 信息
 */
export interface V3proScreenLayout {
  width: number;
  height: number;
  x: number;
  y: number;
  screenID: string;
}

/**
 * starriver 显示屏下所有状态
 */
export interface V3proScreenAllStatus extends Record {
  deviceInfo: V3proScreen;
  status: {
    power: string;
    uptimeS: number;
  };
  sendBoxs: V3proSendBox[];
  layout: V3proScreenLayout;
  isAbsolute: boolean;
}

/**
 * 外部设备状态
 * 1. 亮度传感器
 */
export interface V3proExternalDeviceStatus {
  value: number;
  queryTime: string;
  health: HealthEnum;
}
